package com.teradyne.merlin2.ui.client.presenter;

import java.util.List;

import com.google.common.collect.Lists;
import com.google.gwt.activity.shared.Activity;
import com.google.gwt.event.shared.EventBus;
import com.google.gwt.event.shared.HandlerRegistration;
import com.google.gwt.user.client.ui.AcceptsOneWidget;

public abstract class BasePresenter implements Activity {

	private List<HandlerRegistration> registrations = Lists.newLinkedList();

	protected abstract void bind();
	
	protected abstract void events(EventBus eventBus);

	/**
	 * Unregister all the handlers in particular activity
	 */
	public void unbind() {
		for (HandlerRegistration registration : registrations) {
			registration.removeHandler();
		}
		registrations.clear();
	}
	
	/**
	 * 
	 * @param registration - register the handler and add to the list of handlers
	 */

	protected void addHandler(HandlerRegistration registration) {
		registrations.add(registration);
	}
	
	@Override
	public abstract void start(AcceptsOneWidget panel, EventBus eventBus);

}
